package com.azt.novel.user.controller;


import com.azt.novel.common.auth.UserHolder;
import com.azt.novel.common.resp.RestResp;
import com.azt.novel.user.dto.req.UserLoginReqDto;
import com.azt.novel.user.dto.req.UserRegisterReqDto;
import com.azt.novel.user.dto.resp.UserInfoRespDto;
import com.azt.novel.user.dto.resp.UserLoginRespDto;
import com.azt.novel.user.dto.resp.UserRegisterRespDto;
import com.azt.novel.user.service.IUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author azt
 * @since 2023-12-02
 */
@RestController
@RequestMapping("/api/front/user")
public class UserInfoController {

    @Resource
    private IUserInfoService iUserInfoService;

    @Operation(summary = "获取用户信息")
    @GetMapping
    public RestResp<UserInfoRespDto> getUserinfo(){
        return iUserInfoService.getUserinfo(UserHolder.getUserId());
    }

    /**
     * 用户登录接口
     */
    @Operation(summary = "用户登录接口")
    @PostMapping("/login")
    public RestResp<UserLoginRespDto> login(@Valid @RequestBody UserLoginReqDto dto){
        return iUserInfoService.login(dto);
    }
    /**
     * 用户注册接口
     */
    @Operation(summary = "用户注册接口")
    @PostMapping("register")
    public RestResp<UserRegisterRespDto> register(@Valid @RequestBody UserRegisterReqDto dto) {
        return iUserInfoService.register(dto);
    }

}
